<!DOCTYPE html>






  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.2.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.2.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '6.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '884IXKDARU',
      apiKey: '73268cbd2090d14ab01f9fd7b9874762',
      indexName: 'hexo-blogs',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="很喜欢zsh的git aliases，也希望带到其他电脑上使用，或Windows上的Git使用； 于是乎研究了一下Git aliases在Bash下的自动补全，发现确实可行，所以分享一下给大家； 创建文件 ~/.bash_aliases.git，包含以下内容： __linux_git_complete_file=/usr/share/bash-completion/completions/git">
<meta name="keywords" content="Bash,Git">
<meta property="og:type" content="article">
<meta property="og:title" content="Git Aliases Tab补全">
<meta property="og:url" content="http://linkscue.com/2015/05/20/bash-git-aliases-complete/index.html">
<meta property="og:site_name" content="Linkscue&#39;s blogs">
<meta property="og:description" content="很喜欢zsh的git aliases，也希望带到其他电脑上使用，或Windows上的Git使用； 于是乎研究了一下Git aliases在Bash下的自动补全，发现确实可行，所以分享一下给大家； 创建文件 ~/.bash_aliases.git，包含以下内容： __linux_git_complete_file=/usr/share/bash-completion/completions/git">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-03-12T01:57:15.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Git Aliases Tab补全">
<meta name="twitter:description" content="很喜欢zsh的git aliases，也希望带到其他电脑上使用，或Windows上的Git使用； 于是乎研究了一下Git aliases在Bash下的自动补全，发现确实可行，所以分享一下给大家； 创建文件 ~/.bash_aliases.git，包含以下内容： __linux_git_complete_file=/usr/share/bash-completion/completions/git">



  <link rel="alternate" href="/atom.xml" title="Linkscue's blogs" type="application/atom+xml" />




  <link rel="canonical" href="http://linkscue.com/2015/05/20/bash-git-aliases-complete/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Git Aliases Tab补全 | Linkscue's blogs</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Linkscue's blogs</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">清風有情君意愜, 夢徊怡江詩心緣。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>




<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://linkscue.com/2015/05/20/bash-git-aliases-complete/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linkscue(scue)">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/assets/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Linkscue's blogs">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Git Aliases Tab补全
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2015-05-20 00:00:00" itemprop="dateCreated datePublished" datetime="2015-05-20T00:00:00+08:00">2015-05-20</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2018-03-12 09:57:15" itemprop="dateModified" datetime="2018-03-12T09:57:15+08:00">2018-03-12</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/技术/" itemprop="url" rel="index"><span itemprop="name">技术</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>很喜欢zsh的git aliases，也希望带到其他电脑上使用，或Windows上的Git使用；</p>
<p>于是乎研究了一下Git aliases在Bash下的自动补全，发现确实可行，所以分享一下给大家；</p>
<p>创建文件 <code>~/.bash_aliases.git</code>，包含以下内容：</p>
<pre><code>__linux_git_complete_file=/usr/share/bash-completion/completions/git
__windows_git_complete_file=/etc/bash_completion.git
__host_os_type=$(uname -sm)

case ${__host_os_type:0:5} in
    Linux)
        __current_git_complete_file=$__linux_git_complete_file
        ;;
    MINGW)
        __current_git_complete_file=$__windows_git_complete_file
        ;;
    *)
        echo &quot;Warning: .bash_alias.git unknow host os type !&quot;
        ;;
esac

test -e $__current_git_complete_file &amp;&amp; source $__current_git_complete_file

unset __host_os_type
unset __linux_git_complete_file
unset __windows_git_complete_file
unset __current_git_complete_file

# Aliases
alias g=&apos;git&apos;
alias gst=&apos;git status&apos;
alias gd=&apos;git diff&apos;
alias gdc=&apos;git diff --cached&apos;
alias gl=&apos;git pull&apos;
alias gup=&apos;git pull --rebase&apos;
alias gp=&apos;git push&apos;
alias gc=&apos;git commit -v&apos;
alias gc!=&apos;git commit -v --amend&apos;
alias gca=&apos;git commit -v -a&apos;
alias gca!=&apos;git commit -v -a --amend&apos;
alias gcmsg=&apos;git commit -m&apos;
alias gco=&apos;git checkout&apos;
alias gcm=&apos;git checkout master&apos;
alias gr=&apos;git remote&apos;
alias grv=&apos;git remote -v&apos;
alias grmv=&apos;git remote rename&apos;
alias grrm=&apos;git remote remove&apos;
alias grset=&apos;git remote set-url&apos;
alias grup=&apos;git remote update&apos;
alias grbi=&apos;git rebase -i&apos;
alias grbc=&apos;git rebase --continue&apos;
alias grba=&apos;git rebase --abort&apos;
alias gb=&apos;git branch&apos;
alias gba=&apos;git branch -a&apos;
alias gcount=&apos;git shortlog -sn&apos;
alias gcl=&apos;git config --list&apos;
alias gcp=&apos;git cherry-pick&apos;
alias glg=&apos;git log --stat --max-count=10&apos;
alias glgg=&apos;git log --graph --max-count=10&apos;
alias glgga=&apos;git log --graph --decorate --all&apos;
alias glo=&apos;git log --oneline --decorate --color&apos;
alias glog=&apos;git log --oneline --decorate --color --graph&apos;
alias gss=&apos;git status -s&apos;
alias ga=&apos;git add&apos;
alias gm=&apos;git merge&apos;
alias grh=&apos;git reset HEAD&apos;
alias grhh=&apos;git reset HEAD --hard&apos;
alias gclean=&apos;git reset --hard &amp;&amp; git clean -dfx&apos;
alias gwc=&apos;git whatchanged -p --abbrev-commit --pretty=medium&apos;

#remove the gf alias
#alias gf=&apos;git ls-files | grep&apos;

alias gpoat=&apos;git push origin --all &amp;&amp; git push origin --tags&apos;
alias gmt=&apos;git mergetool --no-prompt&apos;

alias gg=&apos;git gui citool&apos;
alias gga=&apos;git gui citool --amend&apos;
alias gk=&apos;gitk --all --branches&apos;

alias gsts=&apos;git stash show --text&apos;
alias gsta=&apos;git stash&apos;
alias gstp=&apos;git stash pop&apos;
alias gstd=&apos;git stash drop&apos;

# Will cd into the top of the current repository
# or submodule.
alias grt=&apos;cd $(git rev-parse --show-toplevel || echo &quot;.&quot;)&apos;

# Git and svn mix
alias git-svn-dcommit-push=&apos;git svn dcommit &amp;&amp; git push github master:svntrunk&apos;

alias gsr=&apos;git svn rebase&apos;
alias gsd=&apos;git svn dcommit&apos;
#
# Will return the current branch name
# Usage example: git pull origin $(current_branch)
#
function current_branch() {
  ref=$(git symbolic-ref HEAD 2&gt; /dev/null) || \
  ref=$(git rev-parse --short HEAD 2&gt; /dev/null) || return
  echo ${ref#refs/heads/}
}

function current_repository() {
  ref=$(git symbolic-ref HEAD 2&gt; /dev/null) || \
  ref=$(git rev-parse --short HEAD 2&gt; /dev/null) || return
  echo $(git remote -v | cut -d&apos;:&apos; -f 2)
}

# these aliases take advantage of the previous function
alias ggpull=&apos;git pull origin $(current_branch)&apos;
alias ggpur=&apos;git pull --rebase origin $(current_branch)&apos;
alias ggpush=&apos;git push origin $(current_branch)&apos;
alias ggpnp=&apos;git pull origin $(current_branch) &amp;&amp; git push origin $(current_branch)&apos;

# these alias ignore changes to file
alias gignore=&apos;git update-index --assume-unchanged&apos;
alias gunignore=&apos;git update-index --no-assume-unchanged&apos;
# list temporarily ignored files
alias gignored=&apos;git ls-files -v | grep &quot;^[[:lower:]]&quot;&apos;

# Git Aliases AutoComplete
type __git_complete &gt;/dev/null 2&gt;&amp;1 &amp;&amp; {
    __git_complete   g        _git
    __git_complete   gd       _git_diff
    __git_complete   gdc      _git_diff
    __git_complete   gl       _git_pull
    __git_complete   gup      _git_pull
    __git_complete   gp       _git_push
    __git_complete   gc       _git_commit
    __git_complete   gc!      _git_commit
    __git_complete   gca      _git_commit
    __git_complete   gca!     _git_commit
    __git_complete   gcmsg    _git_commit
    __git_complete   gco      _git_checkout
    __git_complete   gcm      _git_checkout
    __git_complete   gr       _git_remote
    __git_complete   grv      _git_remote
    __git_complete   grmv     _git_remote
    __git_complete   grrm     _git_remote
    __git_complete   grset    _git_remote
    __git_complete   grup     _git_remote
    __git_complete   grbi     _git_rebase
    __git_complete   grbc     _git_rebase
    __git_complete   grba     _git_rebase
    __git_complete   gb       _git_branch
    __git_complete   gba      _git_branch
    __git_complete   gcount   _git_shortlog
    __git_complete   gcl      _git_config
    __git_complete   gcp      _git_cherry_pick
    __git_complete   glg      _git_log
    __git_complete   glgg     _git_log
    __git_complete   glgga    _git_log
    __git_complete   glo      _git_log
    __git_complete   glog     _git_log
    __git_complete   gss      _git_log
    __git_complete   ga       _git_add
    __git_complete   gm       _git_merge
    __git_complete   grh      _git_reset
    __git_complete   grhh     _git_reset
    __git_complete   gwc      _git_whatchanged
    __git_complete   gmt      _git_mergetool
    __git_complete   gk       _gitk
    __git_complete   gsts     _git_stash
    __git_complete   gsta     _git_stash
    __git_complete   gstp     _git_stash
    __git_complete   gstd     _git_stash
    __git_complete   gsr      _git_svn
    __git_complete   gsd      _git_svn
}
</code></pre><p>然后，再让 <code>~/.bashrc</code> 去包含这个文件：</p>
<pre><code>echo &apos;test -e ~/.bash_aliases.git &amp;&amp; . ~/.bash_aliases.git&apos; &gt;&gt; ~/.bashrc
</code></pre><p>然后使用类似命令<code>gd</code>、<code>gst</code>、<code>ga</code>和<code>gc</code>等命令简写时，会非常顺手，Enjoy！</p>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Bash/" rel="tag"># Bash</a>
          
            <a href="/tags/Git/" rel="tag"># Git</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/05/20/android-bootup/" rel="next" title="课程3: Android启动过程分析">
                <i class="fa fa-chevron-left"></i> 课程3: Android启动过程分析
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/05/21/iptables-tips/" rel="prev" title="Iptables使用小技巧">
                Iptables使用小技巧 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/assets/images/avatar.png"
                alt="linkscue(scue)" />
            
              <p class="site-author-name" itemprop="name">linkscue(scue)</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">43</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">3</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">29</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/scue" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:scue@vip.qq.com" target="_blank" title="邮箱"><i class="fa fa-fw fa-envelope"></i>邮箱</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://weibo.com/scue" target="_blank" title="微博"><i class="fa fa-fw fa-weibo"></i>微博</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.douban.com/people/scue/" target="_blank" title="豆瓣"><i class="fa fa-fw fa-book"></i>豆瓣</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">linkscue(scue)</span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.6.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Pisces</a> v6.2.0</div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.2.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.2.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.2.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.2.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.2.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.2.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.2.0"></script>



  



	





  





  










  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=6.2.0"></script>



  

  

  

  
  

  
  

  


  
  

  

  

  

  

  

</body>
</html>
